package demo1;

public class MyQueue {

     static class ListNode{
         public int val;
         public ListNode prev;
         public ListNode next;

         public ListNode(int val) {
             this.val = val;
         }
     }
     public ListNode head;
     public ListNode last;

     public void offer(int val){
         ListNode node = new ListNode(val);
       if(isEmpty()){
           head = node;
           last = node;
       }else {
           last.next = node;
           node.prev = last;
           last = node;
       }
     }
     public int poll(){
        if(isEmpty()){
            return -1;
        }
            int val = head.val;
            head = head.next;
            head.prev = null;
        return val;
     }
     public int peek(){
         if(isEmpty()){
             return -1;
         }
         return head.val;
     }
     public int size(){
       ListNode cur = head;
       int count = 0;
       while(head != null){
           count++;
           cur = cur.next;
       }
       return count;
     }
     public boolean isEmpty(){
       return head == null;
     }
}
